package MyPriorityQueue;

import java.util.PriorityQueue;

public class Leetcode0239_Runtime {
    public int[] maxSlidingWindow(int[] nums, int k) {
        int[] ans = new int[nums.length-k+1];
        int cnt = 0;

        PriorityQueue<Integer> pq = new PriorityQueue<>(k, (o1, o2) ->(o2 - o1));
        for(int i=0; i<k; i++){
            pq.add(nums[i]);
        }
        ans[cnt++] = pq.peek();

        for(int i=k; i<nums.length; i++){
            pq.remove(nums[i-k]);
            pq.add(nums[i]);
            ans[cnt++] = pq.peek();
        }
        return ans;
    }
}
